{% extends "base.html" %}
{% block header-content %}
<h3>Event</h3>
<p>Event is an event management system based on the subscribe, unsubscribe model. You can subscribe callbacks, functions, to be run when a fireEvent is called. You can then use AEU_Events.fireEvent(eventName) to fire off all callbacks subscribed to it. AEU_Events is automatically loaded globally when you import the Event class.
</p>
{% endblock %}
{% block content %}
<a href="/event?trigger=true">Click here</a> to trigger an event.<br />
<a href="/event">Click here</a> to view without event triggered (in order to confirm events aren't getting cached by GAE)<br />
msg: {{ msg }}<br />
triggermsg: {{ triggermsg }}
<div class="code">
<h2>webapp class</h2>
<pre>{% filter escape %}class EventPage(webapp.RequestHandler):
  def __init__(self):
        self.msg = ""
        self.triggermsg = "I have not been triggered"

  def get(self):
    if self.request.get('trigger') == "true":
        AEU_Events.subscribe("myTriggeredEventFired", self.myTriggeredCallback, {"msg": "Triggered!"})
    AEU_Events.subscribe("myEventFired", self.myCallback, {"msg": "This message was set in myCallback."})
    AEU_Events.fireEvent("myEventFired")
    AEU_Events.fireEvent("myTriggeredEventFired")
    template_values = {
        'msg': self.msg,
        'triggermsg': self.triggermsg,
    }
    AEU_Events.subscribe("myEventFired", self.myCallback, {"msg": "You will never see this message because the event to set it is fired after the template_values have already been set."})
    AEU_Events.fireEvent("myEventFired")
    path = os.path.join(os.path.dirname(__file__), 'templates/event.html')
    self.response.out.write(template.render(path, template_values))

  def myCallback(self, msg):
    self.msg = msg

  def myTriggeredCallback(self, msg):
    self.triggermsg = msg
{% endfilter %}</pre>
</div>
<div class="code">
<h2>template</h2>
<pre>
{% filter escape %}
<a href="/event?trigger=true">Click here</a> to trigger an event.<br />
<a href="/event">Click here</a> to view without event triggered (in order to confirm events aren't getting cached by GAE)<br />
msg: {% templatetag openvariable %} msg {% templatetag closevariable %}</p>
triggermsg: {% templatetag openvariable %} triggermsg {% templatetag closevariable %}</p>
{% endfilter %}</pre>
</div>
{% endblock %}
